/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138;

import java.io.*;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
//import java.sql.*;
//import org.apache.commons.codec.binary.Base64;

/**
 *
 * @author Vasa
 */
public class ConnectorImpl implements Connector {
    
    public String getXMLFromURL(final String username, final String password, String word, String dictionary)throws IOException
    {
        URL url = new URL("https://deb.fi.muni.cz:8005/" 
                          + dictionary 
                          + "?action=getdoc&id="
                          + word);
        
        Authenticator.setDefault (new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication (username, password.toCharArray());
            }
        });
        
        URLConnection uc = url.openConnection();
        
        InputStream in = uc.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String ret = "";
        String inputLine;
        while((inputLine = reader.readLine())!= null)
        {
            ret += inputLine;
        }
        return ret;
    }
}
